<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-form-item label="活动名称" prop="activityName">
        <el-input
          v-model="queryParams.activityName"
          placeholder="请输入活动名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
	  <el-form-item label="订单编号" prop="activityOrderNo">
	    <el-input
	      v-model="queryParams.activityOrderNo"
	      placeholder="请输入订单编号"
	      clearable
	      size="small"
	      @keyup.enter.native="handleQuery"
	    />
	  </el-form-item>
      <el-form-item label="使用状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择使用状态"
          clearable
          size="small"
        >
          <el-option
            v-for="item in dict.type.order_status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="活动类型" prop="activityType">
        <el-select
          v-model="queryParams.activityType"
          placeholder="请选择活动类型"
          clearable
          size="small"
        >
          <el-option
            v-for="item in dict.type.activity_type"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="activityStartTime">
        <el-date-picker
          v-model="queryParams.activityStartTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择活动开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="activityEndTime">
        <el-date-picker
          v-model="queryParams.activityEndTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择活动结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="支付状态" prop="payStatus">
        <el-select
          v-model="queryParams.payStatus"
          placeholder="请选择支付状态"
          clearable
          size="small"
        >
          <el-option
            v-for="item in dict.type.order_payStatus"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          v-hasPermi="['order:activity:query']"
          >查询</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['order:activity:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column
        min-width="200"
        label="活动名称"
        align="center"
        prop="activityName"
        show-overflow-tooltip
      />
      <el-table-column
        min-width="200"
        show-overflow-tooltip
        label="订单编号"
        align="center"
        prop="activityOrderNo"
      />
      <el-table-column
        min-width="120"
        show-overflow-tooltip
        label="客户名称"
        align="center"
        prop="customerName"
      />
      <el-table-column
        min-width="120"
        label="联系电话"
        align="center"
        prop="customerPhone"
      />
      <el-table-column
        min-width="100"
        label="购买数量/件"
        align="center"
        prop="number"
      />
      <el-table-column
        min-width="80"
        label="支付状态"
        align="center"
        prop="payStatus"
      >
        <template slot-scope="scope">
          {{ scope.row.payStatus | typeFilter(dict.type.order_payStatus) }}
        </template>
      </el-table-column>
      <el-table-column
        min-width="120"
        label="使用状态"
        align="center"
        prop="status"
      >
        <template slot-scope="scope">
          {{ scope.row.status | typeFilter(dict.type.order_status) }}
        </template>
      </el-table-column>
      <el-table-column
        min-width="100"
        label="活动类型"
        align="center"
        prop="activityType"
      >
        <template slot-scope="scope">
          {{ scope.row.activityType | typeFilter(dict.type.activity_type) }}
        </template>
      </el-table-column>
      <el-table-column
        min-width="160"
        label="活动支付总金额/元"
        align="center"
        prop="amount"
        sortable
      />
      <el-table-column
        min-width="160"
        label="下单时间"
        align="center"
        prop="createOrderTime"
        sortable
      />
      <el-table-column
        min-width="160"
        label="是否需要支付"
        align="center"
        prop="isPay"
        sortable
      >
        <template slot-scope="scope">
          {{ scope.row.isPay | typeFilter(dict.type.order_isPay) }}
        </template>
      </el-table-column>
      <el-table-column
        min-width="140"
        label="商品"
        align="center"
        prop="prize"
      />
     <!-- <el-table-column
        min-width="160"
        label="定金"
        align="center"
        prop="downPayment"
        sortable
      /> -->
      <el-table-column
        min-width="140"
        label="适用门店"
        align="center"
        prop="storeName"
      />
      <el-table-column
        min-width="160"
        label="活动开始时间"
        align="center"
        prop="activityStartTime"
      />
      <el-table-column
        min-width="160"
        label="活动结束时间"
        align="center"
        prop="activityEndTime"
      />
      <el-table-column
        min-width="160"
        label="支付时间"
        align="center"
        prop="payTime"
      />

      <el-table-column
        min-width="80"
        label="支付方式"
        align="center"
        prop="payWay"
      >
        <template slot-scope="scope">
          {{ scope.row.payWay | typeFilter(dict.type.order_payWay) }}
        </template>
      </el-table-column>
      <el-table-column
         min-width="160"
         label="退款时间"
         align="center"
         prop="refundTime"
       />
     <!-- 
      <el-table-column
        min-width="160"
        label="组团开始时间"
        align="center"
        prop="groupStartTime"
      />
      <el-table-column
        min-width="160"
        label="组团结束时间"
        align="center"
        prop="groupEndTime"
      />
      <el-table-column
        min-width="80"
        label="组团人数"
        align="center"
        prop="groupPeople"
      />
      <el-table-column
        min-width="160"
        label="发放时间"
        align="center"
        prop="grantTime"
      />

      <el-table-column
        min-width="80"
        label="报名客户"
        align="center"
        prop="customersBooking"
      />
      <el-table-column
        min-width="120"
        label="报名客户手机号"
        align="center"
        prop="customersBookingPhone"
      />
      <el-table-column
        min-width="160"
        label="创建时间"
        align="center"
        prop="createTime"
      />
      <el-table-column
        min-width="120"
        label="创建人"
        align="center"
        prop="createBy"
      />
      <el-table-column
        min-width="160"
        label="修改时间"
        align="center"
        prop="updateTime"
      />
      <el-table-column
        min-width="120"
        label="修改人"
        align="center"
        prop="updateBy"
      />
      <el-table-column
        min-width="160"
        label="说明"
        align="center"
        prop="orderExplain"
      /> -->
      <el-table-column
        min-width="140"
        label="操作"
        align="center"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handDetail(scope.row)"
            >详情</el-button
          >
          <!-- 使用状态为未使用支持退款（status == 1&& activityType==1）-->
          <el-button
            v-if="scope.row.status == 1 && scope.row.activityType == 1"
            size="mini"
            type="text"
            @click="handRefund(scope.row)"
            >退款</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getActivityList,
  refundActivity,
  exportActivity,
} from '@/api/order/activity'

export default {
  name: 'OrderActive',
  components: {},
  dicts: [
    'order_status',
    'order_payStatus',
    'activity_type',
    'order_isPay',
    'order_payWay',
  ],
  data() {
    return {
      showSearch: true,
      // 表格遮罩
      loading: false,
      // 表格数据
      list: [],
      total: 1,
      // 导出遮罩层
      exportLoading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        activityName: '',
		activityOrderNo:'',
        status: null,
        activityType: null,
        activityStartTime: '',
        activityEndTime: '',
        payStatus: null,
      },
    }
  },
  filters: {
    typeFilter(val, type) {
      if (val === null) return null
      let data = type.filter((item) => {
        return val == item.value
      })
      if (data.length) {
        return data[0].label
      } else {
        return val
      }
    },
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询租户管理列表 */
    getList() {
      this.loading = true
      getActivityList(this.queryParams).then((response) => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
		this.form = response.data;
		this.list.forEach(item=>{
			let arr=[];
			for(let i of item.serviceInfoList){
				arr.push(i.shoppingServiceName)
			}
			item.prize=arr.join(",");
		})
		
		
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 详情按钮操作 */
    handDetail(row) {
      this.$router.push({
        path: '/order/activity/detail/' + row.activityOrderNo,
      })
    },
    /** 退款按钮操作 */
    handRefund(row) {
			let message, ids
			if (row) {
			  message ='是否确认退款订单号为[ ' + row.activityOrderNo + ' ]的数据项？'
			} else {
			  message = '是否确认退款？'
			}
			this.$modal.confirm(message).then((e) => {
			  refundActivity({ activityOrderNo: row.activityOrderNo }).then((res) => {
			    this.$message.success(res.msg)
			    this.getList()
			  })
			})

    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = {
        activityName: this.queryParams.activityName,
        activityOrderNo: this.queryParams.activityOrderNo,
        status: this.queryParams.status,
        activityStartTime: this.queryParams.activityStartTime,
        activityEndTime: this.queryParams.activityEndTime,
        payStatus: this.queryParams.payStatus,
      }
      this.$modal
        .confirm('是否确认导出活动订单数据项？')
        .then(() => {
          this.exportLoading = true
          exportActivity(queryParams)
            .then((res) => {
              this.$download.name(res.msg)
              this.exportLoading = false
            })
            .catch((err) => {
              this.exportLoading = false
            })
        })
        .catch(() => {})
    },
  },
}
</script>
